import type {BaseRsp, DelParamsType, ListData, PageParamsType} from "@/api/index";
import {useAxios} from "@/api/index";

// 登录
export interface EmailLoginReq {
    user_name: string
    pwd: string
}

export interface EmailLoginRsp {
    token: string
}

export function loginAxios(params: EmailLoginReq): Promise<BaseRsp<EmailLoginRsp>> {
    return useAxios.post("/admin/user/email_login", params)
}

// 注销登录
export function logoutAxios(): Promise<BaseRsp<string>> {
    return useAxios.post("/admin/user/logout")
}

// 用户列表
export interface UserListRsp {
    id: number
    created_at: string
    nick_name: string
    user_name: string
    password: string
    avatar: string
    email: string
    tel: string
    addr: string
    token: string
    ip: string
    role: number
    sign_status: number
}

export function userListAxios(params: PageParamsType): Promise<BaseRsp<ListData<UserListRsp>>> {
    return useAxios.get("/admin/user/list", {params})
}

// 添加用户
export interface UserInfoAddReq {
    nick_name: string
    user_name: string
    password: string
    role: number
}

export function userAddAxios(params: UserInfoAddReq): Promise<BaseRsp<boolean>> {
    return useAxios.post("/admin/user/add", params)
}

// 修改用户
export interface UserInfoUpdateReq {
    id: number
    role: number
    nick_name: string
}

export function userUpdateAxios(params: UserInfoUpdateReq): Promise<BaseRsp<boolean>> {
    return useAxios.put("/admin/user/update", params)
}

// 删除用户
export function userDelAxios(params: DelParamsType): Promise<BaseRsp<boolean>> {
    return useAxios.delete("/admin/user/del", {data: params})
}
